public class Solution {
    //宝石与石头
    public int numJewelsInStones(String jewels, String stones) {
        int n = stones.length();
        int count = 0;
        for(int i = 0; i < n; i++) {
            if(isContains(jewels,stones.charAt(i))) {
                count++;
            }
        }
        return count;
    }
    public boolean isContains(String jewels, char c){
        int n = jewels.length();
        boolean sign = false;
        for(int i = 0; i < n; i++) {
            if(c == jewels.charAt(i)) {
                sign = true;
            }
        }
        return sign;
    }

    //快乐数
    public boolean isHappy(int n) {
        //定义快慢指针，慢指针每次走一步，快指针速度为慢指针两倍
        int slow = n;
        int fast = n;
        while(true) {
            slow = squrt(slow);
            fast = squrt(fast);
            fast = squrt(fast);
            if(slow == fast) {
                break;
            }
        }
        //相遇后判断循环
        return fast == 1;
    }
    //计算一次数字平方和
    public int squrt(int num) {
        int sum = 0;
        while(num > 0) {
            int n = num % 10;
            num = num / 10;
            sum = sum + n * n;
        }
        return sum;
    }
}
